package net.simflow.swf.analyzer.chart;

import java.util.ArrayList;
import java.util.TreeSet;

import net.simflow.swf.analyzer.bgnetwork.data.BGNode;
import net.simflow.swf.analyzer.bgnetwork.stats.data.BGNetworkStats;
import net.simflow.swf.analyzer.data.StringConstant;
import net.simflow.swf.analyzer.data.TupleStrInt;

public class BGOneStatsChart {

	private static BGOneStatsChart instance = new BGOneStatsChart();

	private BGOneStatsChart() {
	}

	public static BGOneStatsChart getInstance() {
		return instance;
	}

	public ArrayList<TupleStrInt> generate(String style, String name,
			BGNode node) {
		if (style == BGNetworkStats.ONE_GRAPH_NAME) {
			return this.getNameString(style, name);
		} else if (style == BGNetworkStats.ONE_NEIGHBOR) {
			return this.getNeighborString(style, node);
		}
		return null;
	}

	private ArrayList<TupleStrInt> getNameString(String title, String name) {
		ArrayList<TupleStrInt> info = new ArrayList<TupleStrInt>();
		info.add(new TupleStrInt(title, StringConstant.TITLE));
		info.add(new TupleStrInt(name, StringConstant.CONTENT));
		return info;
	}

	private ArrayList<TupleStrInt> getNeighborString(String title, BGNode node) {
		if (node == null) {
			return null;
		}

		TreeSet<String> set = new TreeSet<String>();
		for (BGNode n : node.getNeighborSet()) {
			set.add(n.getNameInBG());
		}
		set.comparator();

		ArrayList<TupleStrInt> info = new ArrayList<TupleStrInt>();
		info.add(new TupleStrInt(title + ": " + node.getNameInBG() + " ("
				+ node.getNeighborSet().size() + ")", StringConstant.TITLE));
		for (String str : set) {
			info.add(new TupleStrInt(str.toString(), StringConstant.CONTENT));
		}

		return info;
	}
}
